# 商品接口

import requests

from base.base_request import MerRequests
from base.base_url import MerProductUrl, MerKeyLibraryUrl, MerClassificationUrl
from base.decorator import print_execution


class MerProduct(MerRequests, MerProductUrl):

    @print_execution
    def mer_product_list(self, cateId='', keywords=''):  # 商品列表
        params = {
            'page': '1',
            'limit': '20',
            'cateId': cateId,
            'keywords': keywords,
            'type': '2',
            'temp': '1761817606',
        }
        return self.get(self.mer_product_list.__name__, url=self.KEY_product_list, params=params, )

    @print_execution
    def mer_product_template(self,id,templateId=[]):  # 设置运费
        json_data = {
            'id': id,
            'templateId': templateId,
        }
        return self.post(self.mer_product_template.__name__, url=self.KEY_product_template, data=json_data, )

    @print_execution
    def mer_product_brokerage(self, idList=[], brokerage=1, brokerageTwo=1):  # 设置佣金
        json_data = {
            'brokerage': brokerage,
            'brokerageTwo': brokerageTwo,
            'id': 3258,
            'idList': idList,
        }

        return self.post(self.mer_product_brokerage.__name__, url=self.KEY_product_brokerage, data=json_data, )

    @print_execution
    def mer_product_coupons(self, id, couponIds=[]):  # 设置优惠券
        json_data = {
            'id': id,
            'couponIds': couponIds,
        }
        return self.post(self.mer_product_coupons.__name__, url=self.KEY_product_coupons, data=json_data, )

    def mer_product_delete(self, id):  # 商品删除
        json_data = {
            'id': id,
            'type': 'recycle',
        }

        return self.post(self.mer_product_delete.__name__, url=self.KEY_product_delete, data=json_data, )

    @print_execution
    def mer_product_restore(self, id):  # 商品恢复
        url = f'{self.KEY_product_restore}/{id}'
        json_data = {'id': id, }
        return self.post(self.mer_product_restore.__name__, url, data=json_data, )


class MerKeyLibrary(MerRequests, MerKeyLibraryUrl):

    @print_execution
    def mer_key_library_page_list(self, name=None, productName=''):  # 卡密列表
        params = {
            'page': '1',
            'limit': '20',
            'name': name,
            'productName': productName,
            'temp': '1761814460',
        }
        return self.get(self.mer_key_library_page_list.__name__, url=self.KEY_key_library_page_list, params=params, )

    @print_execution
    def mer_key_library_save(self, name=None, remark=''):  # 新增卡密
        json_data = {
            'name': name,
            'remark': remark,
            'id': 0,
        }
        return self.post(self.mer_key_library_save.__name__, url=self.KEY_key_library_save, data=json_data, )

    @print_execution
    def mer_key_library_delete(self,id=None):  # 删除卡密
        url = f'{self.KEY_key_library_delete}/{id}'
        return self.post(self.mer_key_library_delete.__name__, url, )

    @print_execution
    def mer_key_library_update(self, name=None, remark=''):  # 更新卡密
        json_data = {
            'name': name,
            'remark': remark,
            'id': 134,
            'usedNum': 0,
            'totalNum': 2,
            'createTime': '2025-10-16 11:32:34',
            'productName': '',
            'productAttrValueName': '',
        }
        return self.post(self.mer_key_library_update.__name__, url=self.KEY_key_library_update, data=json_data, )

    @print_execution
    def mer_card_secret_page_list(self,id=None):  # 卡密编辑的列表
        params = {
            'page': '1',
            'limit': '20',
            'libraryId': id,
            'temp': '1761814898',
        }
        return self.get(self.mer_card_secret_page_list.__name__, url=self.KEY_card_secret_page_list, params=params, )


class MerClassification(MerRequests, MerClassificationUrl):

    @print_execution
    def classification_list(self):  # 分类列表
        params = {'temp': '1761815933', }
        return self.get(self.classification_list.__name__, url=self.KEY_classification_list, params=params, )

    @print_execution
    def classification_add(self, name=None):  # 分类添加
        json_data = {
            'icon': None,
            'name': name,
            'pid': 0,
            'sort': 1,
            'id': 0,
        }
        return self.post(self.classification_add.__name__, url=self.KEY_classification_add, data=json_data, )

    @print_execution
    def classification_update_show(self,id=None):  # 分类更新显示
        url = f'{self.KEY_classification_update_show}/{id}'
        return self.post(self.classification_update_show.__name__, url, )

    @print_execution
    def classification_delete(self,id=None):  # 分类删除
        url = f'{self.KEY_classification_delete}/{id}'
        return self.post(self.classification_delete.__name__, url, )


if __name__ == '__main__':
    mer_product = MerProduct()
    print(mer_product.mer_product_list())
    # print(mer_product.mer_product_brokerage())
    # print(mer_product.mer_product_template())
    # print(mer_product.mer_product_coupons())
    # print(mer_product.mer_product_delete())
    # print(mer_product.mer_product_restore())
    #
    # mer_key = MerKeyLibrary()
    # print(mer_key.mer_key_library_page_list())
    # print(mer_key.mer_key_library_save())
    # print(mer_key.mer_key_library_update())
    # print(mer_key.mer_card_secret_page_list())
    # print(mer_key.mer_key_library_delete())
    #
    # mer_fication = MerClassification()
    # print(mer_fication.classification_list())
    # print(mer_fication.classification_add())
    # print(mer_fication.classification_update_show())
    # print(mer_fication.classification_delete())
